<!--  通关管理 批量下载随附单据失败弹窗 -->
<template>
    <Modal
        v-model="batchDownloadFailModal"
        width="746"
        class="col-2"
        :closable="false"
    >
        <div slot="header">
            批量下载随附单据失败
            <Icon class="f-fr" type="ios-close" @click="closeModal"/>
        </div>
        <Table :columns="columns" :data="failList"></Table>
        <div slot="footer">
            <Button type="default" @click="closeModal">取消</Button>
            <Button type="primary" @click="continueHandle" :disabled="disabled">继续下载</Button>
        </div>
    </Modal>
</template>

<script>
import { getToken } from '@/libs/util.js'
import { downloadURL } from '@/config/downloadUrl.js'

export default {
    name: 'BatchDownloadFailModal',
    data () {
        return {
            batchDownloadFailModal: false,
            columns: [
                {
                    title: '内部编号',
                    key: 'relNo'
                },
                {
                    title: '错误原因',
                    key: 'message'
                }
            ],
            successList: [],
            failList: [],
            disabled: false
        }
    },
    methods: {
        init (list) {
            this.batchDownloadFailModal = true
            this.successList = []
            this.failList = []
            list.forEach(item => {
                if (item.flag) {
                    this.successList.push(item)
                } else {
                    this.failList.push(item)
                }
            })
            if (this.successList.length === 0) {
                this.disabled = true
            } else {
                this.disabled = false
            }
        },

        closeModal () {
            this.batchDownloadFailModal = false
        },

        continueHandle () {
            console.log(this.successList)
            let tempArr = []
            this.successList.forEach(item => {
                tempArr.push(item.rowNum)
            })
            let data = {
                params: {
                    declareIds: tempArr.join()
                },
                Authorization: getToken()
            }
            let params = encodeURI(JSON.stringify(data.params))
            let url = downloadURL + '/ui/dataFileDownload/downloadDeclareFiles?param=' + params + '&Authorization=' + data.Authorization
            window.open(url)
        }
    }
}
</script>

<style scoped>

</style>
